package com.github.shiqiyue.app.api.sapi.result.role;


import com.github.shiqiyue.app.common.entity.TreeNode;
import com.github.shiqiyue.app.modules.sys.entity.Role;
import lombok.Data;

import java.util.List;

/***
 * 角色树VO
 * @author wenyao.wu
 * @date 2018/10/16
 */
@Data
public class RoleTreeDTO implements TreeNode {

    private Long id;

    /**
     * 名称
     */
    private String name;

    /**
     * 角色编码
     */
    private String code;

    /**
     * 是否可用，-1-不可用，1-可用
     */
    private Integer enable;

    /**
     * 上级id
     */
    private Long pid;

    /***
     * 子节点
     */
    private List<RoleTreeDTO> children;

    public RoleTreeDTO() {
    }

    public static RoleTreeDTO newInstance(Role role) {
        RoleTreeDTO roleTreeDTO = new RoleTreeDTO();
        roleTreeDTO.setId(role.getId());
        roleTreeDTO.setPid(role.getPid());
        roleTreeDTO.setCode(role.getCode());
        roleTreeDTO.setName(role.getName());
        roleTreeDTO.setEnable(role.getEnable().getValue());
        return roleTreeDTO;
    }

    @Override
    public void setChildren(List children) {
        this.children = children;
    }
}
